package xm.chengdu.com.sbglxt;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import base.Z_UserInfoDao;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;
import javabean.Bean;
import javabean.XXXX;
import utils.JSONUtils;

public class Success_Activity extends Activity {


    @BindView(R.id.img_back)
    RelativeLayout imgBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.textView11)
    TextView textView11;
    @BindView(R.id.layout_help)
    RelativeLayout layoutHelp;
    @BindView(R.id.textView8)
    View textView8;
    @BindView(R.id.layout_zuo)
    RelativeLayout layoutZuo;
    @BindView(R.id.textView2)
    TextView textView2;
    @BindView(R.id.layout_zhong)
    RelativeLayout layoutZhong;
    @BindView(R.id.textView6)
    View textView6;
    @BindView(R.id.layout_you)
    RelativeLayout layoutYou;
    @BindView(R.id.layout_szmx)
    LinearLayout layoutSzmx;
    @BindView(R.id.imageView12)
    ImageView imageView12;
    @BindView(R.id.wd)
    TextView wd;
    @BindView(R.id.tv_wd)
    TextView tvWd;
    @BindView(R.id.imcyzgz)
    ImageView imcyzgz;
    @BindView(R.id.sd)
    TextView sd;
    @BindView(R.id.tv_sd)
    TextView tvSd;
    @BindView(R.id.imfwjdk)
    ImageView imfwjdk;
    @BindView(R.id.mqnd)
    TextView mqnd;
    @BindView(R.id.tv_mqnd)
    TextView tvMqnd;
    @BindView(R.id.imfwjdk2)
    ImageView imfwjdk2;
    @BindView(R.id.yw)
    TextView yw;
    @BindView(R.id.tv_yw)
    TextView tvYw;
    @BindView(R.id.tv_tms)
    TextView tv_tms;
    @BindView(R.id.et_fs)
    TextView et_fs;

    Z_UserInfoDao z_userInfoDao;
String ss="{\"temp\":\"18\",\"state\":\"0\",\"speed\":\"88\",\"alarm\":\"0\",\"time\":\"2019,3,26,12,34\"} ";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_success_2);
        EventBus.getDefault().register(this);
        ButterKnife.bind(this);
        z_userInfoDao = new Z_UserInfoDao(this);
        sss(ss);
    }
String zhuangtai="";
    String baojing="";
    public void onEventMainThread(MyEvent event) {
        if (!TextUtils.isEmpty(event.getType())) {

            sss(event.getContent());
        }
    }
public  void sss(String xxxx2){
    XXXX xxxx = JSONUtils.parseJSON(xxxx2, XXXX.class);
        String Temp = xxxx.getTemp();
        String State = xxxx.getState();
        String Speed = xxxx.getSpeed();
        String Alarm = xxxx.getAlarm();
        String Time = xxxx.getTime();

        tvWd.setText(Temp+ "度");



        if (State.equals("0")) {
            zhuangtai="关闭";
            tvSd.setText("关闭");
        } else {
            zhuangtai="开启";
            tvSd.setText("开启");
        }
        tvMqnd.setText(Speed + "r/min");
        if (Alarm.equals("0")) {
            tvYw.setText("有报警");
            baojing="有报警";
        } else {
            baojing="无报警";
            tvYw.setText("无报警");
        }

        tv_tms.setText(Time.replace(",", ":"));
        z_userInfoDao.addUser(Temp+ "度",zhuangtai,Speed + "r/min",baojing,Time.replace(",", ":"));
    }


;
    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @OnClick({R.id.img_back, R.id.kaiqi, R.id.guanbi, R.id.sz, R.id.shuju})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();

                break;
            case R.id.shuju:
                startActivity(new Intent(this, JieMian.class));

                break;
            case R.id.kaiqi:
                Bean bean = new Bean();
                bean.setFan("1");
                String o = JSONUtils.tojson(bean);
                MyEvent myEvent1 = new MyEvent();
                myEvent1.setContent(o);
                myEvent1.setType("message");

                EventBus.getDefault().post(myEvent1);
                break;
            case R.id.guanbi:
                Bean bean2 = new Bean();
                bean2.setFan("0");
                String o2 = JSONUtils.tojson(bean2);
                MyEvent myEvent = new MyEvent();
                myEvent.setContent(o2);
                myEvent.setType("message");
                EventBus.getDefault().post(myEvent);
                break;
            case R.id.sz:
                String s = et_fs.getText().toString();
                if (TextUtils.isEmpty(s)) {
                    Toast.makeText(this, "请输入风速", Toast.LENGTH_SHORT).show();
                    return;
                }
                Bean bean3 = new Bean();
                bean3.setSpeed(s);
                String o3 = JSONUtils.tojson(bean3);
                MyEvent myEvent3 = new MyEvent();
                myEvent3.setContent(o3);
                myEvent3.setType("message");
                EventBus.getDefault().post(myEvent3);
                break;

        }
    }


}
